//----------------------------------Include------------------------------------
#include "my_mcu.h"
//-----------------------------------------------------------------------------

//-----------------------------------Macro-------------------------------------
//-----------------------------------------------------------------------------

//--------------------------------Public Func----------------------------------
void MyMcu_Init_SPI(void)
{
  stc_spi_config_t  stcCfg;
  
//enable clock
  Clk_SetPeripheralGate(ClkPeripheralSpi, TRUE);
  
//pin
  //Gpio_SetFunc_SPI_CS_P03();
  Gpio_SetFunc_SPIMISO_P23();
  Gpio_SetFunc_SPIMOSI_P24();
  Gpio_SetFunc_SPICLK_P25();
  //Spi_SetCS(TRUE);
  
//config
  stcCfg.bCPHA       = Spicphafirst;
  stcCfg.bCPOL       = Spicpollow;
  stcCfg.bIrqEn      = FALSE;
  stcCfg.bMasterMode = SpiMaster;
  stcCfg.u8BaudRate  = SpiClkDiv2;
  stcCfg.pfnIrqCb    = NULL;
  Spi_Init(&stcCfg);
}

u8 MyMcu_SPI1_RdWrByte(u8 TxData)
{
  u32 retry=0;
  
  M0P_SPI->DATA = TxData;
  while( ! Spi_GetStatus(SpiIf) ){
    if(++retry > 200) return 0;
  }
  
  return M0P_SPI->DATA;
}
//------------------------------------ISR--------------------------------------
//-----------------------------------------------------------------------------

//------------------------------------EOF--------------------------------------





